﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using SharpShare.Utilities;

namespace SharpShare.Storage.Filter {
    public class FilteredStorageFile : FilteredStorageItem, IStorageFile {
        internal FilteredStorageFile(IStorageFile baseFile, IStorageFilter filter, IStorageContainer parent)
            : base(baseFile, filter, parent) {

        }

        public new IStorageFile BaseItem { get { return (IStorageFile)base.BaseItem; } }

        #region IStorageFile Members

        public long Length {
            get { return this.BaseItem.Length; }
        }

        public IStorageDataProvider Open(StorageFileAccess access, StorageFileAccess share) {
            return this.BaseItem.Open(access, share);
        }

        #endregion

        internal static FilteredStorageFile Create(IStorageFile baseFile, IStorageFilter filter, IStorageContainer parent) {
            return ObjectCache<FilteredStorageFile>
                .ByKey<Tuple<IStorageFile, IStorageFilter, IStorageContainer>>
                    .GetOrCreate(
                        Tuple.Create(baseFile, filter, parent),
                        k => new FilteredStorageFile(baseFile, filter, parent));
        }
    }
}
